/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","ojs/ojeditablevalue","ojs/ojradiocheckbox"],function(a,g){(function(){a.Ra("oj.ojCheckboxset",g.oj.editableValue,{version:"1.0.0",defaultElement:"\x3cdiv\x3e",widgetEventPrefix:"oj",options:{disabled:!1,value:void 0},refresh:function(){this._super();this.ab()},widget:function(){return this.YLa},Yf:function(b,d){var e=[],f;this._super(b,d);a.Fe.Cp([{ha:"disabled",Sd:!0},{ha:"title"},{ha:"placeholder"},{ha:"required",wh:!0,Sd:!0}],d,this);this.sg=this.TS();void 0===d.value&&
(f=this.sg.filter(":checked"),0<f.length&&(f.each(function(){e.push(g(this).val())}),this.option("value",e,{_context:{Cd:!0,kb:!0}})),void 0===this.options.value&&(this.options.value=[]))},_ComponentCreate:function(){this._super();if(this.element.is("fieldset"))throw Error("ojCheckboxset cannot be bound to a fieldset. Use a div instead.");this.sg._ojRadioCheckbox().attr("data-oj-internal",!0);this.YLa=this.element.addClass("oj-checkboxset oj-component").attr("role","group").wrapInner("\x3cdiv class\x3d'oj-checkboxset-wrapper'\x3e\x3c/div\x3e");
this._on(this.xq);this.ab()},CQ:function(){this.sg=this.TS();this.sg.filter(".oj-checkbox").each(function(){var a=void 0!==g(this).attr("disabled")?!!g(this).prop("disabled"):!1;g(this)._ojRadioCheckbox("option","disabled",a)});this.sg.not(".oj-checkbox")._ojRadioCheckbox()},Focus:function(){this.Xf().first().focus();return!0},FQ:function(){},TS:function(){var b=this.element.find("input[type\x3dcheckbox]:first");0===b.length&&a.t.warn("Could not find any input type\x3dcheckbox within this element");
b=b.attr("name");return void 0===b?(b=this.element.find("input[type\x3dcheckbox]"),b.not("[name]")):this.element.find("input[type\x3dcheckbox][name\x3d"+b+"]")},ph:function(a,b,e){a=this.element.find("input[type\x3dcheckbox]:tabbable").first();this.qh(b,e,{launcher:a})},_GetMessagingLauncherElement:function(){return this.widget()},ab:function(){this.et(this.options.disabled);null!==this.sg&&(1===this.sg.length?this.element.addClass("oj-checkboxset-single"):this.element.removeClass("oj-checkboxset-single"))},
xq:{change:function(a){this.pH(a)}},pH:function(a){var d;d=this.sg;0<d.length&&d.each(function(){this===a.target&&g(this)._ojRadioCheckbox("setSelectedClass",a.target.checked)});d=this.Si();this.wc(d,a,b)},Si:function(){return this.Zx()},Hl:function(a){var b=this.sg.length,e,f,h;for(f=0;f<b;f++){h=g(this.sg[f]);e=h[0].value;e=a.indexOf(e);var k=h._ojRadioCheckbox("option","checked");-1!==e?k||h._ojRadioCheckbox("option","checked",!0):k&&h._ojRadioCheckbox("option","checked",!1)}},Zx:function(){var a=
[],b=this.sg.filter(":checked");if(0===b.length)return[];b.each(function(){a.push(g(this).val())});return a},_GetDefaultStyleClass:function(){return"oj-checkboxset"},Xf:function(){if(null!=this.sg)return this.sg;this.TS()},zQ:function(){},PB:function(){return!0},et:function(a){a=!!a;this.sg.each(function(){g(this).data("oj-_ojRadioCheckbox").lC(a)});this.sg._ojRadioCheckbox("refreshDisabled")},_setOption:function(a,b,e){this._super(a,b,e);"disabled"===a&&this.et(b)},getNodeBySubId:function(a){var b=
this._super(a);return b||(a=a.subId,"oj-checkboxset-inputs"!==a)?b||null:this.sg.get()},_destroy:function(){var a=this._super(),b=this.element[0].firstChild;this.sg&&this.sg._ojRadioCheckbox("destroy");g(b).contents().unwrap();return a}});var b={Fw:!1}})();a.Components.Xa("ojCheckboxset","editableValue",{properties:{disabled:{type:"boolean"},value:{type:"Array"}},methods:{destroy:{},refresh:{},widget:{}},extension:{_widgetName:"ojCheckboxset"}});a.Components.register("oj-checkboxset",a.Components.getMetadata("ojCheckboxset"))});